#include <iostream>
using namespace std;

const int kMaxN = 15e5 + 10;

int right_bound[kMaxN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, a;
  int ans;

  cin >> n >> m;
  ans = n;
  for (int i = 1; i <= n; i++) {
    int left_bound = max(1, i - m + 1);

    cin >> a;
    if (right_bound[a] + 1 < left_bound) {
      ans = min(a, ans);
    }
    right_bound[a] = i;
  }
  for (int i = 0; i < ans; i++) {
    if (right_bound[i] <= n - m) {
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}